package com.nsn.auction.domina;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="ITEM")
public class Item {
	
	private String name;
	private StringBuffer matter;
	private Long itemId;
	
	public Item() {}
	
	public Item(String name, StringBuffer matter) {
		this.name = name;
		this.matter = matter;
	}
	
	@Column(name="NAME", unique = false, nullable = false, length = 30)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(name="MATTER", unique = false, nullable = false, length = 200)
	public StringBuffer getMatter() {
		return matter;
	}
	
	public void setMatter(StringBuffer matter) {
		this.matter = matter;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="ITEM_ID", unique = false, nullable = false, length = 30)
	public Long getItemId() {
		return itemId;
	}
	
	public void setItemId(Long itemId) {
		this.itemId = itemId;
	}
	
	@Override
	public boolean equals(Object object) {
		
		//check for selt-comparison
		if (this == object) return true;
		if (!( this.getClass().equals(object.getClass()) )) return false;
		
		Item temp_item = (Item) object;
		 return (null == getName() ? null == temp_item.getName() : getName().equals(temp_item.getName()) && 
				null == getMatter().toString() ? null == temp_item.getMatter().toString() : getMatter().toString().equals(temp_item.getMatter().toString()));
	}
	
}
